<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>fetch</title>
    <script src="lib/vue.js"></script>
</head>

<body>
    <p>get方法:</p><br>
    <p>fetch("").then(res.json()).then(res=>{console.log(res)})</p>
    <p>fetch("").then(res.text()).then(res=>{console.log(res)})</p>
    <hr>
    <p>post方法:</p>
    <p>fetch("*",{
        method:"post",
        headers:{
        ”content-Type":"application/x-www-form-urlencoded"
        }
        }).then(res.json()).then(res=>{console.log(res)})</p>
    <hr>

    <div id="box">

        <button @click="handleClick">通过fetch方法请求数据</button>

        <ul>
            <li v-for="data in datalist" :key="data.channelid">{{data.name}}</li>
        </ul>

    </div>



    <script>
        new Vue({
            el: "#box",
            data: {
                datalist: []
            },
            methods: {
                handleClick() {
                    fetch("https://api.apiopen.top/musicBroadcasting").then(res => {
                        return res.json()
                    }).then(res => {
                        console.log(res.result[0].channellist);
                        this.datalist = res.result[0].channellist
                    })
                }
            }
        })
    </script>
</body>

</html>